/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.form;

import java.util.List;

import org.rails.extjs.Option;

public class DateField extends TextField {

	public DateField() {
		super();
	}

	public DateField(Option configOptions) {
		super(configOptions);
	}
	
	public DateField(String name) {
		super(name);
	}

	public DateField(String name, String fieldLabel) {
		super(name, fieldLabel);
	}

	public DateField(String name, String fieldLabel, String value) {
		super(name, fieldLabel, value);
	}

	public void setAltFormats(String altFormats) {
		addOption("altFormats", altFormats);
	}

	public String getAltFormats() {
		return getString("altFormats",
				"m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d");
	}
	
	public void setDisabledDates(List<String> disabledDates){
		addOption("disabledDates", disabledDates);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getDisabledDates(){
		return (List<String>)getOption("disabledDates");
	}
	
	public void setDisabledDatesText(String disabledDatesText){
		addOption("disabledDatesText", disabledDatesText);
	}
	
	public String getDisabledDatesText(){
		return getString("disabledDatesText", "Disabled");
	}
	
	public void setDisabledDays(List<String> disabledDays){
		addOption("disabledDays", disabledDays);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getDisabledDays(){
		return (List<String>)getOption("disabledDays");
	}
	
	public void setDisabledDaysText(String disabledDaysText){
		addOption("disabledDaysText",disabledDaysText);
	}
	
	public String getDisabledDaysText(){
		return getString("disabledDaysText","Disabled");
	}
	
	public void setFormat(String format){
		addOption("format", format);
	}
	
	public String getFormat(){
		return getString("format", "m/d/Y");
	}
	
	public void setInvalidText(String invalidText){
		addOption("invalidText", invalidText);
	}
	
	public String getInvalidText(){
		return getString("invalidText", "{value} is not a valid date - it must be in the format {format}");
	}
	
	public void setMaxText(String maxText){
		addOption("maxText", maxText);
	}
	
	public String getMaxText(){
		return getString("maxText","The date in this field must be before {maxValue}");
	}
	
	public void setMaxValue(String maxValue){
		addOption("maxValue", maxValue);
	}
	
	public String getMaxValue(){
		return getString("maxValue", "");
	}
	
	public void setMinText(String minText){
		addOption("minText", minText);
	}
	
	public String getMinText(){
		return getString("minText","The date in this field must be before {minValue}");
	}
	
	public void setMinValue(String minValue){
		addOption("minValue", minValue);
	}
	
	public String getMinValue(){
		return getString("minValue", "");
	}
	
	public void setShowToday(Boolean showToday){
		addOption("showToday", showToday);
	}
	
	public Boolean isShowToday(){
		return getBoolean("showToday",true);
	}
	
	public void setTriggerClass(String triggerClass){
		addOption("triggerClass", triggerClass);
	}
	
	public String getTriggerClass(){
		return getString("triggerClass", "x-form-date-trigger");
	}
	
	@Override
	public Tag getAutoCreate(){
		Tag con = new Tag();
		con.setSize(10);
		con.setAutocomplete("off");
		return getOption("autoCreate") == null ? con : (Tag)getOption("autoCreate");
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.form.DateField(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}
	

}
